/* Turska Framework/UI library (Turs2)
 * Copyright 2003-2009 Jetro Lauha
 * All rights reserved.
 * Web: http://iki.fi/jetro/turska/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of EITHER:
 *   (1) The GNU Lesser General Public License as published by the Free
 *       Software Foundation; either version 2.1 of the License, or (at
 *       your option) any later version. The text of the GNU Lesser
 *       General Public License is included with this library in the
 *       file LICENSE-LGPL.txt.
 *   (2) The BSD-style license that is included with this library in
 *       the file LICENSE-BSD.txt.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
 * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
 *
 * $Id: T2ImageIrr.h 131 2009-06-05 05:58:05Z jlauha $
 * $Revision: 131 $
 */

#ifndef T2IMAGEIRR_H_INCLUDED
#define T2IMAGEIRR_H_INCLUDED


namespace irr
{
    namespace video
    {
        class ITexture;
    }
}

namespace turska
{
    class GraphicsIrr;

    //! Implementation of Turska Image which uses Irrlicht.
    /*! \note In this implementation, IF_ALPHA flag affects only whole image
     *        transparency. Each pixel color is always alpha blended.
     */
    class ImageIrr : public turska::Image
    {
    public:

        //! Constructs a new ImageIrr from given texture and U,V coordinates.
        /*!
         * \param width original width of the image in pixels.
         * \param height original height of the image in pixels.
         * \param flags initial flags to use for the image.
         * \param texture irr::video::ITexture to be used as image. Texture is
         *                grabbed and dropped when this object is deleted.
         * \param uv array of 2 vectors describing the top-left and
         *           bottom-right U,V coordinates.
         */
        ImageIrr(GraphicsIrr *graphics, UI32 width, UI32 height,
                 UI32 flags, irr::video::ITexture *texture,
                 const irr::core::vector2df *uv);
        virtual ~ImageIrr();

        // From Image:

        virtual void setColor(const Color &color);

        virtual void setTargetSize(REAL width, REAL height) { mTargetWidth = width; mTargetHeight = height; mUsingExplicitTargetSize = true; }
        virtual void resetTargetSize() { mTargetWidth = (F32)mWidth; mTargetHeight = (F32)mHeight; mUsingExplicitTargetSize = false; }

        virtual void setAngle(REAL angle) { mAngle = angle; }

        virtual void setScale(REAL scale) { mScaleX = mScaleY = scale; }
        virtual void setScale(REAL scaleX, REAL scaleY) { mScaleX = scaleX; mScaleY = scaleY; }

        virtual void draw(REAL x, REAL y) { draw(mDrawMode, mFlags, x, y); }
        virtual void draw(IMAGE_DRAW_MODE drawMode, UI32 flags, REAL x, REAL y, const Rectangle *sourceRect = 0) { draw(drawMode, flags | IF_FILTER_LINEAR, x, y, mColor, sourceRect); }
        virtual void draw(IMAGE_DRAW_MODE drawMode, UI32 flags, REAL x, REAL y, const Color &color, const Rectangle *sourceRect = 0);

        // ImageIrr additions:

        inline irr::video::ITexture * getIrrTexture() const { return mTexture; }
        inline irr::core::vector2df * getUV() { return mUV; }

    protected:

        void draw(IMAGE_DRAW_MODE drawMode, UI32 flags, F32 x, F32 y,
                  const irr::video::SColor &color, const Rectangle *sourceRect);

        GraphicsIrr *mGraphics;
        irr::video::IVideoDriver *mDriver;
        irr::video::ITexture *mTexture;
        irr::core::vector2df mUV[2];
        const F32 mHalfWidth;
        const F32 mHalfHeight;
        irr::video::SColor mColor;
        F32 mTargetWidth;
        F32 mTargetHeight;
        F32 mAngle;
        F32 mScaleX, mScaleY;
        bool mUsingExplicitTargetSize;
    }; // ImageIrr
} // namespace turska


#endif // !T2IMAGEIRR_H_INCLUDED
